#pragma once
#ifndef __SPLITTOOL_H__
#define __SPLITTOOL_H__
#include "cppjieba/Jieba.hpp"
#include <memory>
#include <string>
#include <vector>
using std::string;
using std::vector;

const char* const DICT_PATH = "../conf/dict/jieba.dict.utf8";
const char* const HMM_PATH = "../conf/dict/hmm_model.utf8";
const char* const USER_DICT_PATH = "../conf/dict/user.dict.utf8";
const char* const IDF_PATH = "../conf/dict/idf.utf8";
const char* const STOP_WORD_PATH = "../conf/dict/stop_words.utf8";

class SplitTool
{
public:
    virtual void cut(const string& sentence,vector<string>& words) = 0;
    virtual ~SplitTool(){};
};

class SplitToolCppJieba
:public SplitTool
{
    class AutoRelease{
    public:
        AutoRelease(){}
        ~AutoRelease(){
            if(_pInstance){
                delete _pInstance;
                _pInstance = nullptr;
            }
        }
    };
private:
    SplitToolCppJieba()
        :jieba(DICT_PATH,
               HMM_PATH,
               USER_DICT_PATH,
               IDF_PATH,
               STOP_WORD_PATH)
    {}
public:
    void cut(const string& sentence,vector<string>& words) override{
        jieba.Cut(sentence,words,true);
    }
    static SplitToolCppJieba* getInstance(){
        if(_pInstance==nullptr){
            _pInstance = new SplitToolCppJieba();
        }
        return _pInstance;
    }

private:
    cppjieba::Jieba jieba;
    static SplitToolCppJieba* _pInstance;
    static AutoRelease _ar;
};
#endif
